---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
  labels:
    app: jenkins
    section: tools
spec:
  ports:
    - name: http-port
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: jenkins
    section: tools
  clusterIP: None

---
apiVersion: v1
kind: Service
metadata:
  name: jenkins-0
  namespace: jenkins
  labels:
    app: jenkins
    section: tools
spec:
  ports:
    - name: http-port
      port: 8080
      protocol: TCP
      targetPort: 8080
    - name: jnlp-port
      port: 50000
      protocol: TCP
      targetPort: 50000
  selector:
    app: jenkins
    section: tools
    statefulset.kubernetes.io/pod-name: jenkins-0

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: jenkins
  namespace: jenkins
  labels:
    app: jenkins
    section: tools
spec:
  replicas: 1
  serviceName: jenkins
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
        section: tools
    spec:
      serviceAccountName: jenkins-account
      imagePullSecrets:
        - name: kryukov-local
      containers:
      - name: jenkins
        image: n.kryukov.local/bigkaa/jenkins:v0.1
        imagePullPolicy: IfNotPresent
        env:
          - name: JAVA_OPTS
#            value: "-Xms2g -Xmx2g -Djenkins.install.runSetupWizard=false"
            value: "-Xms2g -Xmx2g"
          - name: JENKINS_SLAVE_AGENT_PORT
            value: "50000"
#            - name: JENKINS_OPTS
#              value: "--prefix=/jenkins"
        livenessProbe:
          httpGet:
            path: "/prometheus/"
            port: 8080
          initialDelaySeconds: 90
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 5
        readinessProbe:
          httpGet:
            path: "/prometheus/"
            port: 8080
          initialDelaySeconds: 60
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        ports:
          - name: http-port
            containerPort: 8080
          - name: jnlp-port
            containerPort: 50000
        resources:
          requests:
            memory: "256Mi"
            cpu: "50m"
          limits:
            memory: "2Gi"
            cpu: "2"
        volumeMounts:
          - name: jenkins-home
            mountPath: /var/jenkins_home
  volumeClaimTemplates:
    - metadata:
        name: jenkins-home
      spec:
        accessModes: [ "ReadWriteOnce" ]
        storageClassName: "managed-nfs-storage"
        resources:
          requests:
            storage: 8Gi

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
  name: jenkins
  namespace: jenkins
  labels:
    app: jenkins
    section: tools
spec:
  rules:
    - host: j.kryukov.local
      http:
        paths:
          - backend:
              serviceName: jenkins-0
              servicePort: 8080
            path: /